package common

import (
	. "go-caipu/pkg/services/sqlstore/migrator"
)

func AddOnlineUserMigrations(mg *Migrator) {
	onlineUser := Table{
		Name: "sys_online_user",
		Columns: []*Column{
			{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
			{Name: "user_id", Type: DB_NVarchar, Length: 40, Nullable: true},
			{Name: "token", Type: DB_NVarchar, Length: 300, Nullable: false},
			{Name: "user_name", Type: DB_NVarchar, Length: 32, Nullable: true},
			{Name: "nick_name", Type: DB_NVarchar, Length: 64, Nullable: false},
			{Name: "ip", Type: DB_NVarchar, Length: 64, Nullable: true},
			{Name: "location", Type: DB_NVarchar, Length: 300, Nullable: true},
			{Name: "browser", Type: DB_NVarchar, Length: 64, Nullable: true},
			{Name: "os", Type: DB_NVarchar, Length: 64, Nullable: true},
			{Name: "login_time", Type: DB_DateTime, Length: 6, Nullable: true},
			{Name: "last_active_at", Type: DB_DateTime, Length: 6, Nullable: true},
		},
		Indices: []*Index{
			{Cols: []string{"token", "ip", "os"}, Type: UniqueIndex},
		},
	}
	//create table
	mg.AddMigration("create table sys_Online_user", NewAddTableMigration(onlineUser))
	// index
	mg.AddMigration("add index Ix_online_userId_token_ip", NewAddIndexMigration(onlineUser, onlineUser.Indices[0]))
}
